//
//  HWHomeInformationCell.swift
//  HWanGame
//
//  Created by Apple on 2024/8/1.
//  Copyright © 2024 94Wan. All rights reserved.
//

import UIKit

class HWHomeInformationCell: UITableViewCell {

    var iconImageView = UIImageView()
    var nameLabel = UILabel()
    var timeLabel = UILabel()
    private let dianLabel = c_make_ex(UILabel.self)
        .color("#AEB0B3").font(9.font_medium).text("·")
        .alignment(.center).end()
    private let lookButton = UIIconButton(style: .leading(itemSpace: 2))
    private let commitButton = UIIconButton(style: .leading(itemSpace: 2))
    
    var model:HWHomeInfoItemModel?{
        didSet {
            guard let md = model else { return }
            iconImageView.sd_setImage(with: URL(string: md.image))
            nameLabel.text = md.title
            timeLabel.text = md.time_format
            lookButton.setTitle(md.look, for: .normal)
            commitButton.setTitle(md.pinglun, for: .normal)
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.addSubview(iconImageView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(dianLabel)
        contentView.addSubview(lookButton)
        contentView.addSubview(commitButton)
        
        iconImageView.layer.cornerRadius = 8
        iconImageView.layer.masksToBounds = true
        iconImageView.contentMode = .scaleAspectFill

        nameLabel.font = 16.font_medium
        nameLabel.textColor = UIColor.colorWithHexString(hexString: "#2E3033")
        nameLabel.numberOfLines = 2
        
        timeLabel.font = 10.font_medium
        timeLabel.textColor = UIColor.colorWithHexString(hexString: "#AEB0B3")
        
        lookButton.style { v in
            v.iconSize = CGSize(width: 12*widthScale, height: 12*widthScale)
            v.setImage("Small_look".toImage, for: .normal)
            v.setTitleColor("#AEB0B3".toColor, for: .normal)
            v.titleLabel?.font = 10.font_medium
            v.isUserInteractionEnabled = false
//            v.contentHorizontalAlignment = .right
        }
        
        commitButton.style { v in
            v.iconSize = CGSize(width: 12*widthScale, height: 12*widthScale)
            v.setImage("Small_commit".toImage, for: .normal)
            v.setTitleColor("#AEB0B3".toColor, for: .normal)
            v.titleLabel?.font = 10.font_medium
            v.isUserInteractionEnabled = false
//            v.contentHorizontalAlignment = .right
        }
        
        iconImageView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12*widthScale)
            make.top.equalToSuperview().offset(12*widthScale)
            make.width.equalTo(136*widthScale)
            make.height.equalTo(78*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.leading.equalTo(iconImageView.snp.trailing).offset(12*widthScale)
            make.trailing.equalToSuperview().offset(-12*widthScale)
            make.top.equalTo(iconImageView)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.leading.equalTo(iconImageView.snp.trailing).offset(12*widthScale)
            make.trailing.equalToSuperview().offset(-130*widthScale)
            make.bottom.equalTo(iconImageView)
        }
        
        commitButton.snp.makeConstraints { make in
            make.height.equalTo(12*widthScale)
            make.trailing.equalToSuperview().offset(-12*widthScale)
            make.centerY.equalTo(timeLabel)
        }
        
        dianLabel.snp.makeConstraints { make in
            make.trailing.equalTo(commitButton.snp.leading)
            make.centerY.equalTo(commitButton)
        }
        
        lookButton.snp.makeConstraints { make in
            make.height.equalTo(12*widthScale)
            make.trailing.equalTo(dianLabel.snp.leading)
            make.centerY.equalTo(timeLabel)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

class HWHomeInfoCateCell: UICollectionViewCell {

    private let contentButton = UIButton()
        
    var model:HWHomeInfoCateModel?{
        didSet{
            guard let md = model else { return }
            contentButton.isSelected = md.isSel
            contentButton.setTitle(md.name, for: .normal)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.addSubview(contentButton)

        contentButton.setTitleColor(.black, for: .selected)
        contentButton.setTitleColor(UIColor.colorWithHexString(hexString: "#808080"), for: .normal)
        contentButton.titleLabel?.font = UIFont.systemFont(ofSize: 16*widthScale, weight: .medium)//PingFangSC-Medium
        contentButton.isUserInteractionEnabled = false
        
        contentButton.snp.makeConstraints { make in
            make.centerY.centerX.equalToSuperview()
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
